Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

full comparison of candidates #3702

Merged
merged 3 commits into from
Dec 6, 2022
Merged

full comparison of candidates #3702

merged 3 commits into from
Dec 6, 2022

Conversation

CoderZhi
Copy link
Collaborator

@CoderZhi CoderZhi commented Dec 1, 2022

fix #3700
Current implementation only compares votes and owner addresses. This pr adds more comparisons, which includes all fields in candidate.

Fixes #(issue)

Type of change

Please delete options that are not relevant.

  • [] Bug fix (non-breaking change which fixes an issue)
  • [] New feature (non-breaking change which adds functionality)
  • [] Code refactor or improvement
  • [] Breaking change (fix or feature that would cause a new or changed behavior of existing functionality)
  • [] This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • [] make test
  • [] fullsync
  • [] Other test (please specify)

Test Configuration:

  • Firmware version:
  • Hardware:
  • Toolchain:
  • SDK:

Checklist:

  • [] My code follows the style guidelines of this project
  • [] I have performed a self-review of my code
  • [] I have commented my code, particularly in hard-to-understand areas
  • [] I have made corresponding changes to the documentation
  • [] My changes generate no new warnings
  • [] I have added tests that prove my fix is effective or that my feature works
  • [] New and existing unit tests pass locally with my changes
  • [] Any dependent changes have been merged and published in downstream modules

@CoderZhi CoderZhi requested a review from a team as a code owner December 1, 2022 21:28
@codecov
Copy link

codecov bot commented Dec 1, 2022

Codecov Report

Merging #3702 (976418b) into master (263ff82) will decrease coverage by 0.50%.
The diff coverage is 83.29%.

❗ Current head 976418b differs from pull request most recent head aada847. Consider uploading reports for the commit aada847 to get more accurate results

@@            Coverage Diff             @@
##           master    #3702      +/-   ##
==========================================
- Coverage   74.47%   73.96%   -0.51%     
==========================================
  Files         269      291      +22     
  Lines       23925    24722     +797     
==========================================
+ Hits        17818    18286     +468     
- Misses       5174     5502     +328     
- Partials      933      934       +1     
Impacted Files Coverage Δ
action/protocol/staking/candidate_statereader.go 53.94% <ø> (-3.38%) ⬇️
action/protocol/types.go 0.00% <0.00%> (ø)
api/web3server.go 27.59% <0.00%> (-34.51%) ⬇️
db/db_bolt.go 68.53% <0.00%> (-3.60%) ⬇️
ioctl/newcmd/action/actiontransfer.go 100.00% <ø> (ø)
ioctl/newcmd/action/stake2withdraw.go 95.74% <ø> (ø)
ioctl/newcmd/action/xrc20transferfrom.go 100.00% <ø> (ø)
ioctl/newcmd/did/didgethash.go 100.00% <ø> (ø)
ioctl/newcmd/did/didgeturi.go 100.00% <ø> (ø)
server/itx/server.go 62.20% <ø> (+2.20%) ⬆️
... and 45 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@dustinxie
Copy link
Member

dustinxie commented Dec 2, 2022

not sure if it's necessary to make this change, should also follow the suggestions in #3700

@@ -253,7 +253,37 @@ func (l CandidateList) Less(i, j int) bool {
if res := l[i].Votes.Cmp(l[j].Votes); res != 0 {
return res == 1
}
return strings.Compare(l[i].Owner.String(), l[j].Owner.String()) == 1
switch strings.Compare(l[i].Owner.String(), l[j].Owner.String()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

func (l CandidateList) Less(i, j int) bool {
	if res := l[i].Votes.Cmp(l[j].Votes); res != 0 {
		return res == 1
	}
	if res := strings.Compare(l[i].Owner.String(), l[j].Owner.String()); res != 0 {
		return res == 1
	}
	if res := strings.Compare(l[i].Operator.String(), l[j].Operator.String()); res != 0 {
		return res == 1
	}
	return strings.Compare(l[i].Name, l[j].Name) == 1
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. @Liuhaai agree comparing these 2 fields should suffice, and I think since we fix this compare func now, we'd better compare all fields to cover all possible corner cases
  2. prefer to use
if res != 0 {
		return res == 1
	}

to be consistent, instead of switch case

@sonarcloud
Copy link

sonarcloud bot commented Dec 5, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
48.8% 48.8% Duplication

case -1:
return false
if res := strings.Compare(l[i].Operator.String(), l[j].Operator.String()); res != 0 {
return res == 1
}
switch {
case l[i].SelfStakeBucketIdx > l[j].SelfStakeBucketIdx:
return true
case l[i].SelfStakeBucketIdx < l[j].SelfStakeBucketIdx:
return false
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if l[i].SelfStakeBucketIdx != l[j].SelfStakeBucketIdx {
return l[i].SelfStakeBucketIdx > l[j].SelfStakeBucketIdx
}

@dustinxie dustinxie merged commit f86d079 into master Dec 6, 2022
@dustinxie dustinxie deleted the candidate_less branch December 6, 2022 03:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

candidate fix not complete
4 participants